package org.dromara.system.controller.system;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysUserEmptyOrderRecordsBo;
import org.dromara.system.domain.vo.SysUserEmptyOrderRecordsVo;
import org.dromara.system.service.ISysUserEmptyOrderRecordsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 空单记录
 *
 * @author Lion Li
 * @date 2025-09-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userEmptyOrderRecords")
public class SysUserEmptyOrderRecordsController extends BaseController {

    private final ISysUserEmptyOrderRecordsService sysUserEmptyOrderRecordsService;

    /**
     * 查询空单记录列表
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:list")
    @GetMapping("/list")
    public TableDataInfo<SysUserEmptyOrderRecordsVo> list(SysUserEmptyOrderRecordsBo bo, PageQuery pageQuery) {
        return sysUserEmptyOrderRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出空单记录列表
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:export")
    @Log(title = "空单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserEmptyOrderRecordsBo bo, HttpServletResponse response) {
        List<SysUserEmptyOrderRecordsVo> list = sysUserEmptyOrderRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "空单记录", SysUserEmptyOrderRecordsVo.class, response);
    }

    /**
     * 获取空单记录详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:query")
    @GetMapping("/{id}")
    public R<SysUserEmptyOrderRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(sysUserEmptyOrderRecordsService.queryById(id));
    }

    /**
     * 新增空单记录
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:add")
    @Log(title = "空单记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserEmptyOrderRecordsBo bo) {
        return toAjax(sysUserEmptyOrderRecordsService.insertByBo(bo));
    }

    /**
     * 修改空单记录
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:edit")
    @Log(title = "空单记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserEmptyOrderRecordsBo bo) {
        return toAjax(sysUserEmptyOrderRecordsService.updateByBo(bo));
    }

    /**
     * 删除空单记录
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userEmptyOrderRecords:remove")
    @Log(title = "空单记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysUserEmptyOrderRecordsService.deleteWithValidByIds(List.of(ids), true));
    }


    @Log(title = "余额充值", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/freezePointsTopUp")
    public R<Void> freezePointsTopUp(@RequestBody SysUserEmptyOrderRecordsBo bo) {
        return toAjax(sysUserEmptyOrderRecordsService.freezePointsTopUp(bo));
    }
}
